package com.l024.meet.fragment.chat;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.l024.framework.base.BaseFragment;
import com.l024.framework.bmob.BmobManager;
import com.l024.framework.bmob.Friend;
import com.l024.framework.utils.CommonUtils;
import com.l024.framework.utils.Logutils;
import com.l024.meet.R;

import java.util.List;

import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;

/**
 * 所有的好友列表
 */
public class AllFriendFragment extends BaseFragment {

    private SwipeRefreshLayout mAllFriendRefreshLayout;
    private RecyclerView mAllFriendView;
    private RelativeLayout itemEmptyView;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_all_record, null);
        initView(view);
        return view;
    }

    private void initView(View view) {
        mAllFriendRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.mAllFriendRefreshLayout);
        mAllFriendView = (RecyclerView) view.findViewById(R.id.mAllFriendView);
        itemEmptyView = (RelativeLayout) view.findViewById(R.id.item_empty_view);
    }

    /**
     * 查询我的所有好友
     */
    private void queryMyFriends(){
        BmobManager.getInstance().queryMyFriends(new FindListener<Friend>() {
            @Override
            public void done(List<Friend> list, BmobException e) {
                if(e==null){
                    if(CommonUtils.isEmpty(list)){
                        itemEmptyView.setVisibility(View.GONE);
                        mAllFriendView.setVisibility(View.VISIBLE);
                    }else{
                        Logutils.e("查询我的好友列表为NULL");
                        itemEmptyView.setVisibility(View.VISIBLE);
                        mAllFriendView.setVisibility(View.GONE);
                    }
                }else{
                    Logutils.e("查询我的好友列表失败："+e);
                    itemEmptyView.setVisibility(View.VISIBLE);
                    mAllFriendView.setVisibility(View.GONE);
                }
            }
        });
    }
}
